'use strict';
// 用户邀请记录
app.controller('inviterecord', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', function ($scope, commonFactory, toaster, $modal, $log) {
    $scope.inviterecordData = {
        Index: 1,
        Size: 10,
        FullName: '',
        Type: '0',
        StartTime: '',
        EndTime: '',
        Mobile: ''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.inviterecordData.Index >= $scope.page) {//判断最大页码
                $scope.inviterecordData.Index = $scope.page;
                return false;
            }
            $scope.inviterecordData.Index++
            requestinviteList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.inviterecordData.Index <= 1) {//判断最小页码
            $scope.inviterecordData.Index = 1;
            return false;
        }
        $scope.inviterecordData.Index--;
        requestinviteList()
    }
    $scope.addUser = function () {
        localStorage.setItem("User", '');
        commonFactory.go("/app/customer/userinfo");
    }
    // 查询
    $scope.queryUser = function () {
        $scope.inviterecordData.Index = 1;
        $scope.graybtn = true;
        if ($scope.inviterecordData.StartTime) {
            $scope.inviterecordData.StartTime = commonFactory.DateFormat($scope.inviterecordData.StartTime);
        } else {
            $scope.inviterecordData.StartTime = ''
        }
        if ($scope.inviterecordData.EndTime) {
            $scope.inviterecordData.EndTime = commonFactory.DateFormat($scope.inviterecordData.EndTime);
        } else {
            $scope.inviterecordData.EndTime = ''
        }
        requestinviteList();
    }
    var requestinviteList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/sharelog/QueryShareLog", $scope.inviterecordData, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            $scope.inviterecord = result.Data;
            $scope.UserListCount = result.Count;
            $scope.page = Math.ceil(result.Count / $scope.inviterecordData.Size);
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requestinviteList()
}]);

// 邀请人信息
app.controller('inviteinfo', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', function ($scope, commonFactory, toaster, $modal, $log) {
    $scope.inviteinfoData = {
        Index: 1,
        Size: 10,
        BossMobile: '19911421923',
        IsInvest: '0',
        Mobile: ''
    }
    var invitemobile = localStorage.getItem("invitemobile");
    if (invitemobile) {
        $scope.inviteinfoData.BossMobile = invitemobile;
    } else{
        commonFactory,go('/app/customer/userinfo')
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.inviteinfoData.Index >= $scope.page) {//判断最大页码
                $scope.inviteinfoData.Index = $scope.page;
                return false;
            }
            $scope.inviteinfoData.Index++
            requestinviteinfoList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.inviteinfoData.Index <= 1) {//判断最小页码
            $scope.inviteinfoData.Index = 1;
            return false;
        }
        $scope.inviteinfoData.Index--;
        requestinviteinfoList()
    }
    $scope.addUser = function () {
        localStorage.setItem("User", '');
        commonFactory.go("/app/customer/userinfo");
    }
    // 查询
    $scope.queryUser = function () {
        $scope.inviteinfoData.Index = 1;
        $scope.graybtn = true;
        requestinviteinfoList();
    }
    var requestinviteinfoList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/Share/MyShares", $scope.inviteinfoData, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            $scope.inviteinfo = result;
            $scope.inviteCount = result.MyShareList.Count;
            $scope.page = Math.ceil(result.MyShareList.Count / $scope.inviteinfoData.Size);
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requestinviteinfoList()
}]);

// 邀请好友初始值设置
app.controller('invitedefault', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', function ($scope, commonFactory, toaster, $modal, $log) {
    var requestInvitedefault = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/share/GetShareInit", {} , function (result) {
            commonFactory.loading(false)
            if (result.Code == 1) {
                $scope.invitedata = result.Data;
            } else {
                toaster.pop('error', '失败', '邀请好友初始值设置查询错误');
            }
        }, function () {
            commonFactory.loading(false)
            toaster.pop('error', '失败', '请求异常');
        }, "get");
    }
    requestInvitedefault()
    $scope.modInvitedefault = function (UserId) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', 'items', function ($scope, $modalInstance, toaster, commonFactory, $timeout, items) {
                $scope.IviteDefault = true;
                $scope.modData = {
                    Price:Number(items.Price)||0,
                    Count:Number(items.Number)||0
                }
                console.log($scope.invitedata)
                $scope.ok = function () {
                    commonFactory.ajax("/api/share/ShareInit", $scope.modData, function (result) {
                        if (result.Code == 1) {
                            toaster.pop('success', '成功', '修改邀请默认值成功');
                            $modalInstance.close('cancel');
                        }else{
                            toaster.pop('error', '失败', '修改邀请默认值错误');
                        }

                    }, function () {
                        toaster.pop('error', '失败', '请求异常');
                    }, "post");
                };
                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'sm',
            backdrop: false,
            resolve: {
                items: function () {
                    return $scope.invitedata;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) { requestInvitedefault() }, function () { });  
    };
}]);

// 用户操作中心
app.controller('customercenter', ['$scope', '$http', 'commonFactory', 'toaster', '$modal', function ($scope, $http, commonFactory, toaster, $modal) {
    var initdata = function () {
        //下一页
        $scope.next = function () {
            if ($scope.page) {
                if ($scope.requestArrcus.pageIndex >= $scope.page) {//判断最大页码
                    $scope.requestArrcus.pageIndex = $scope.page;
                    return false;
                }
                $scope.requestArrcus.pageIndex++
                requestProductList();
            }
        }
        //上一页
        $scope.prev = function () {
            if ($scope.requestArrcus.pageIndex <= 1) {//判断最小页码
                $scope.requestArrcus.pageIndex = 1;
                return false;
            }
            $scope.requestArrcus.pageIndex--;
            requestProductList()
        }
        $scope.requestArrcus = {//查询条件
            pageIndex: 1,
            pageSize: 10,
            username: '',
            userId: '',
            objId:'',
            mobile: '',
            usertransfertype: '',
            usertransferstatus: '',
            begintime: '',
            endtime: '',
            usertransferid: ''
        }
        //查询
        $scope.search = function () {
            $scope.graybtn = true;
            $scope.requestArrcus.pageIndex = 1 //查询后在第一页显示
            if (!$scope.requestArrcus.userId) {
                $scope.requestArrcus.userId = ''
            }
            if (!$scope.requestArrcus.objId) {
                $scope.requestArrcus.objId = ''
            }
            if (!$scope.requestArrcus.username) {
                $scope.requestArrcus.username = ''
            }
            if (!$scope.requestArrcus.mobile) {
                $scope.requestArrcus.mobile = ''
            }
            if (!$scope.requestArrcus.usertransfertype) {
                $scope.requestArrcus.usertransfertype = ''
            }
            if (!$scope.requestArrcus.usertransferstatus) {
                $scope.requestArrcus.usertransferstatus = ''
            }
            if (!$scope.requestArrcus.usertransferid) {
                $scope.requestArrcus.usertransferid = ''
            }
            if ($scope.requestArrcus.begintime) {
                $scope.requestArrcus.begintime = commonFactory.DateFormat($scope.requestArrcus.begintime);
            } else {
                $scope.requestArrcus.begintime = ''
            }
            if ($scope.requestArrcus.endtime) {
                $scope.requestArrcus.endtime = commonFactory.DateFormat($scope.requestArrcus.endtime);
            } else {
                $scope.requestArrcus.endtime = ''
            }
            requestProductList();
        }
        $scope.CompareDate = function(d1){
            d1=d1?d1.substring(0,10):'2018-02-02'
            return ((new Date(d1.replace(/-/g,"\/"))) > (new Date('2018/02/02')));
        }
        var requestProductList = function () {
            commonFactory.loading(true)
            commonFactory.ajax("/api/OtherUserTransfer/QueryGetAllUserTransfer", $scope.requestArrcus, function (result) {
                $scope.graybtn = false;
                commonFactory.loading(false);
                if (result.Code == 1) {
                    result.List.forEach(element => {
                        if (element.ExtendValue) {
                            var msgindex = element.ExtendValue.indexOf(":");
                            element.Extendnum = msgindex != -1 ? element.ExtendValue.substring(0, msgindex) : '';
                            element.ExtendValue = msgindex != -1 ? element.ExtendValue.substring(msgindex + 1) : element.ExtendValue;
                            element.ExtendValue = decodeURIComponent(element.ExtendValue)
                        }
                    });
                    $scope.QueryLoanProductList = result.List;
                    $scope.QueryLoanProductListTotal = result.Total;
                    $scope.page = Math.ceil(result.Total / $scope.requestArrcus.pageSize);
                    $scope.clicktype = function (type) {
                        switch (type) {
                            case 1: return '投标';
                            case 2: return '充值';
                            case 3: return '提现';
                            case 4: return '放款';
                            case 5: return '回款';
                            case 6: return '借款人收款';
                            case 7: return '借款人还款';
                            case 8: return '转账';
                            case 9: return '红包';
                            case 10: return '活期投资';
                            case 11: return '活期退出';
                            case 12: return '活期借款人收款';
                            case 13: return '活期退出借款人扣款';
                            case 14: return '活期发放收益';
                            case 15: return '活期借款人扣利息';
                            case 16: return '复投借款人扣款';
                            case 17: return '复投借款人收钱';
                            case 18: return '网银充值';
                            case 19: return '快速提现';
                            case 20: return '活期提现';
                            case 21: return '奖金';
                        }
                    }

                    $scope.clickstatus = function (obj) {
                        if (obj.UserTransferType == 3 && obj.UserTransferStatus == 4) {
                            return "申请成功";
                        }
                        switch (obj.UserTransferStatus) {
                            case 1: return '新建';
                            case 2: return '成功';
                            case 3: return '失败';
                        }
                    }
                    $scope.getCharge = function (obj) {
                        if(obj.UserTransferType == 19 || obj.UserTransferType == 20){
                            obj.CreateTime = obj.CreateTime.replace('T', ' ')
                            var severseTime = new Date(new Date(obj.CreateTime.replace(/-/g, '/')).getTime()); //订单创建时间
                            var week = severseTime.getDay();
                            if (week == 5 || week == 6 || week == 0) {//周五六日收取3*0.05%手续费
                                var oDate = 3;
                                var newPrice =  obj.Price + "(" + (Math.ceil(obj.Price * 0.05 * oDate) / 100) + ")"
                                return newPrice;
                            } else {
                                var newPrice =  obj.Price + "(" + (Math.ceil(obj.Price * 0.05) / 100) + ")"
                                return newPrice;
                            }

                        }else{
                            var newPrice = obj.Price
                            return newPrice;
                        }
                    }
                    // 订单创建15分钟后显示加息券修复按钮
                    commonFactory.ajax(commonFactory.timeurl+"/api/bank/gettime", {}, function (result) {
                        $scope.serverTime = new Date(result.data.replace(/-/g,"\/"));             
                        $scope.jxqShow = function(obj){
                            var timeslot = 15*60*1000; //按钮显示间隔时间
                            if(obj.UserTransferType==1 && obj.UserTransferStatus==1){
                                var objCreateTime = new Date(obj.CreateTime.replace(/-/g,"\/").replace(/T/g," "));
                                if($scope.serverTime.getTime()-objCreateTime.getTime() > timeslot){
                                    return true
                                }else{
                                    return false;
                                    
                                }
                            }
                        }
                    }, function () { }, 'post') 
                } else {
                    toaster.pop('error', '失败', result.ResposeData);
                }
            }, function () {
                commonFactory.loading(false)
                $scope.graybtn = false;
                toaster.pop('error', '失败', '后台未返回报错');
            }, "post");
        }
        requestProductList();
        $scope.queryStatic = function(ordercode,type){
            if(!ordercode || !type){
                toaster.pop('error', '失败', '缺少objId或操作类型');
                return;
            }
            commonFactory.ajax("/api/OtherUserTransfer/ReviseOperaResult", { orderCode:ordercode ,type:type}, function (result) {
                if (result.Code == 1) {
                    var modalInstance = $modal.open({
                        templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                        controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', function ($scope, $modalInstance, toaster, commonFactory) {
                            if(type == 1 || type == 10){
                                $scope.resposeData = result.ResposeData=="C"?"失败":result.ResposeData=="N"?"成功":"新建"
                            }else if(type == 2 || type == 18 || type == 3 || type == 19 || type == 20){
                                $scope.resposeData = result.ResposeData=="F"?"失败":result.ResposeData=="S"?"成功":"新建"
                            }
                            $scope.queryoderstatic = true;
                            $scope.cancel = function () {
                                $modalInstance.close('cancel');
                            };
                        }],
                        size: 'sm',
                        backdrop: false
                    });
                    modalInstance.result.then(function () {
                        requestProductList();
                    }, function () {

                    });
                    
                } else {
                    toaster.pop('error', '失败', result.ResposeData);
                    $modalInstance.close();
                }
            }, function () {
                toaster.pop('error', '失败', '后台未返回报错');
            }, "post");
        }
        $scope.restoreJxq = function(ordercode){
            if(!ordercode){
                toaster.pop('error', '失败', '缺少objId');
                return;
            }
            commonFactory.ajax("/api/OtherUserTransfer/GetPlusStatus", { orderCode:ordercode}, function (result) {
                if (result.Code == 1) {
                    var modalInstance = $modal.open({
                        templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                        controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', function ($scope, $modalInstance, toaster, commonFactory) {
                            $scope.jxqstatus = result.Data;
                            $scope.queryjxqstatic = true;
                            $scope.cancel = function () {
                                $modalInstance.close('cancel');
                            };
                        }],
                        size: 'sm',
                        backdrop: false
                    });
                    modalInstance.result.then(function () {
                        requestProductList();
                    }, function () {

                    });
                    
                } else {
                    if(result.Data == "未找到待使用的加息卷"){
                        toaster.pop('warning', '提示', "此订单未使用加息券");
                    }else{
                        toaster.pop('error', '失败', result.Data);
                    }
                }
            }, function () {
                toaster.pop('error', '失败', '后台未返回报错');
            }, "get");
        }
    }
    initdata();
}]);

// 用户信息
app.controller('userinfo', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', function ($scope, commonFactory, toaster, $modal, $log) {
    $scope.UserData = {
        Index: 1,
        Size: 10,
        UserId: '',
        FullName: '',
        UsrCustId: '',
        Mobile: ''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.UserData.Index >= $scope.page) {//判断最大页码
                $scope.UserData.Index = $scope.page;
                return false;
            }
            $scope.UserData.Index++
            requestUserList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.UserData.Index <= 1) {//判断最小页码
            $scope.UserData.Index = 1;
            return false;
        }
        $scope.UserData.Index--;
        requestUserList()
    }
    $scope.addUser = function () {
        localStorage.setItem("User", '');
        commonFactory.go("/app/customer/userinfo");
    }
    // 查询
    $scope.queryUser = function () {
        $scope.UserData.Index = 1;
        $scope.graybtn = true;
        requestUserList();
    }
    var requestUserList = function () {
        if ($scope.UserData.UserId != '' || $scope.UserData.FullName != '' || $scope.UserData.UsrCustId != '' || $scope.UserData.Mobile) {
            commonFactory.loading(true)
            commonFactory.ajax("/api/User/UserInfoList", $scope.UserData, function (result) {
                commonFactory.loading(false)
                $scope.graybtn = false;
                if (result.Code == 1) {
                    $scope.UserList = result.UserInfos;
                    $scope.UserListCount = result.Count;
                    $scope.page = Math.ceil(result.Count / $scope.UserData.Size);
                    if ($scope.UserList != null) {
                        for (var i = $scope.UserList.length - 1; i >= 0; i--) {
                            $scope.UserList[i].BirthDate = new Date().getFullYear() - new Date($scope.UserList[i].BirthDate).getFullYear();
                            $scope.UserList[i].CashTotalPrice = Math.abs($scope.UserList[i].CashTotalPrice)
                        }
                    }
                } else {
                    toaster.pop('error', '失败', '用户信息查询错误');
                }
            }, function () {
                commonFactory.loading(false)
                $scope.graybtn = false;
            }, "post");
        } else {
            $scope.graybtn = false;
            toaster.pop('warning', '警告', '请输入任意查询条件');
        }
    }
    // requestUserList()
    $scope.openBank = function (UserId) {
        commonFactory.loading(true)
        commonFactory.ajax("/api/User/UserBanks", { UserId: UserId }, function (result) {
            commonFactory.loading(false)
            if (result.Code == 1) {
                $scope.bankinfo = result.UserBankInfos;
                var modalInstance = $modal.open({
                    templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                    controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', 'items', function ($scope, $modalInstance, toaster, commonFactory, $timeout, items) {
                        $scope.Userbankshow = true;
                        $scope.Userbank = items
                        $scope.cancel = function () {
                            $modalInstance.close('cancel');
                        };
                    }],
                    size: 10,
                    backdrop: false,
                    resolve: {
                        items: function () {
                            return $scope.bankinfo;
                        }
                    }
                });

                modalInstance.result.then(function (selectedItem) { }, function () { });
            }
        }, function () {
            commonFactory.loading(false)
        }, "post");
    };
    $scope.viewDetails = function (mobile) {
        localStorage.setItem("invitemobile", mobile);
        commonFactory.go('/app/customer/inviteinfo');
    }
}]);

//订单查询
app.controller('Orderinquiry', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', '$timeout', function ($scope, commonFactory, toaster, $modal, $log, $timeout) {
    $scope.ordersearch = {
        rechange: '',
        withdraw: '',
        tenderrefund: '',
        tenderinvest: ''
    }
    $scope.queryorder = function () {
        $scope.graybtn = true;
        commonFactory.ajax("/api/bank/GetRecharge", { '': $scope.ordersearch.rechange }, function (result) {//充值
            if (result.Code == 1 && result.Data.Success) {
                $scope.GetRecharge = result.Data.Result;
                $scope.GetWithdraw = "";
                $scope.GettenderInvest = "";
                $scope.GetTenderRefund = ""
            } else {

            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/bank/GetWithdraw", { '': $scope.ordersearch.rechange }, function (result) {//提现
            if (result.Code == 1 && result.Data.Success) {
                $scope.GetWithdraw = result.Data.Result;
                $scope.GetRecharge = "";
                $scope.GettenderInvest = "";
                $scope.GetTenderRefund = ""
            } else {

            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/bank/GetTenderRefund", { '': $scope.ordersearch.rechange }, function (result) {//还款
            if (result.Code == 1 && result.Data.Success) {
                $scope.GetTenderRefund = result.Data.Result;
                $scope.GetRecharge = ''
                $scope.GetWithdraw = "";
                $scope.GettenderInvest = "";
            } else {

            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/bank/GettenderInvest", { '': $scope.ordersearch.rechange }, function (result) {//投标
            if (result.Code == 1 && result.Data.Success) {
                $scope.GettenderInvest = result.Data.Result;
                $scope.GetRecharge = '';
                $scope.GetWithdraw = "";
                $scope.GetTenderRefund = ""
            } else {

            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        $timeout(function () {
            $scope.graybtn = false;
        }, 500);
    }
}]);

// 安心签
app.controller('anxin', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', function ($scope, commonFactory, toaster, $modal, $log) {
    $scope.anxinData = {
        Index: 1,
        Size: 10,
        Template: '',
        Mobile: '',
        ProductCode: '',
        SignStatus: -1
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.anxinData.Index >= $scope.page) {//判断最大页码
                $scope.anxinData.Index = $scope.page;
                return false;
            }
            $scope.anxinData.Index++
            requesAnxinList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.anxinData.Index <= 1) {//判断最小页码
            $scope.anxinData.Index = 1;
            return false;
        }
        $scope.anxinData.Index--;
        requesAnxinList()
    }
    $scope.addUser = function () {
        localStorage.setItem("User", '');
        commonFactory.go("/app/customer/userinfo");
    }
    // 查询
    $scope.queryUser = function () {
        $scope.anxinData.Index = 1;
        $scope.graybtn = true;
        requesAnxinList();
    }
    var requesAnxinList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/Contracts/QuerySignContracts", $scope.anxinData, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            $scope.UserList = result.Data;
            $scope.UserListCount = result.Count;
            $scope.page = Math.ceil(result.Count / $scope.anxinData.Size);
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requesAnxinList()
    $scope.editstatus = function (obj) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'anxinstatus', 'toaster', 'commonFactory', function ($scope, $modalInstance, anxinstatus, toaster, commonFactory) {
                $scope.editStatusData = {
                    Id: anxinstatus,
                    SignTime: "",
                    SignContractCode: ''
                };
                //修改状态 
                $scope.ok = function () {
                    $scope.editStatusData.SignTime = commonFactory.DateFormat($scope.editStatusData.SignTime);
                    commonFactory.ajax("/api/Contracts/SaveSignContract", $scope.editStatusData, function (result) {
                        if (result.Code == 1) {
                            toaster.pop('success', '成功', '授权状态修改成功');
                            $modalInstance.close();
                        } else {
                            toaster.pop('error', '失败', result.ResposeData);
                            $modalInstance.close();
                        }
                    }, function () {
                        toaster.pop('error', '失败', '后台未返回报错');
                    }, "post");
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'sm',
            backdrop: false,
            resolve: {
                anxinstatus: function () {
                    return obj;
                }
            }
        });
        modalInstance.result.then(function () {
            requesAnxinList();
        }, function () {

        });
    }
    $scope.retrySignContract = function (pid) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', function ($scope, $modalInstance, toaster, commonFactory) {
                $scope.showRetrySign = true
                //修改状态 
                $scope.ok = function () {
                    $scope.gray = true;
                    commonFactory.ajax("/api/Contracts/RetrySignContract", { SignContractId: pid }, function (result) {
                        $scope.gray = false;
                        if (result.Code == 1) {
                            toaster.pop('success', '成功', '安心签签署成功');
                            $modalInstance.close();
                        } else {
                            toaster.pop('error', '失败', result.ResposeData);
                            $modalInstance.close();
                        }
                    }, function () {
                        $scope.gray = false;
                        toaster.pop('error', '失败', '后台未返回报错');
                    }, "post");
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'sm',
            backdrop: false
        });
        modalInstance.result.then(function () {
            requesAnxinList();
        }, function () {

        });
    }
}]);
//汇付订单查询
app.controller('hforderinquiry', ['$scope', 'commonFactory', 'toaster', '$modal', '$log', '$timeout', function ($scope, commonFactory, toaster, $modal, $log, $timeout) {
    $scope.ordersearch = {
        rechange: '',
        withdraw: '',
        tenderrefund: '',
        tenderinvest: ''
    }
    $scope.queryorder = function () {
        $scope.graybtn = true;
        commonFactory.ajax("/api/ChinaPnr/QueryTransStat", { ObjId: $scope.ordersearch.rechange, type: 'LOANS' }, function (result) {//充值
            if (result.Code == 1 && result.Data) {
                result.Data.OrdDate = result.Data.OrdDate.substring(0, 4) + '-' + result.Data.OrdDate.substring(4, 6) + '-' + result.Data.OrdDate.substring(6, 8)
                $scope.GetRecharge = result.Data;
            } else {
                $scope.GetRecharge = ''
            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/ChinaPnr/QueryTransStat", { ObjId: $scope.ordersearch.rechange, type: 'CASH' }, function (result) {//提现
            if (result.Code == 1 && result.Data) {
                switch (result.Data.TransStat) {
                    case 'S': result.Data.TransStat = 'S(成功)'; break;
                    case 'F': result.Data.TransStat = 'F(失败)'; break;
                    case 'H': result.Data.TransStat = 'H(经办)'; break;
                    case 'R': result.Data.TransStat = 'R(拒绝)'; break;
                }
                result.Data.OrdDate = result.Data.OrdDate.substring(0, 4) + '-' + result.Data.OrdDate.substring(4, 6) + '-' + result.Data.OrdDate.substring(6, 8)
                $scope.GetWithdraw = result.Data;
            } else {
                $scope.GetWithdraw = ''
            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/ChinaPnr/QueryTransStat", { ObjId: $scope.ordersearch.rechange, type: 'REPAYMENT' }, function (result) {//还款
            if (result.Code == 1 && result.Data) {
                switch (result.Data.TransStat) {
                    case 'I': result.Data.TransStat = 'I(初始)'; break;
                    case 'P': result.Data.TransStat = 'P(部分成功)'; break;
                }
                result.Data.OrdDate = result.Data.OrdDate.substring(0, 4) + '-' + result.Data.OrdDate.substring(4, 6) + '-' + result.Data.OrdDate.substring(6, 8)
                $scope.GetTenderRefund = result.Data;
            } else {
                $scope.GetTenderRefund = ''
            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/ChinaPnr/QueryTransStat", { ObjId: $scope.ordersearch.rechange, type: 'TENDER' }, function (result) {//投标
            if (result.Code == 1 && result.Data) {
                switch (result.Data.TransStat) {
                    case 'I': result.Data.TransStat = 'I(初始)'; break;
                    case 'N': result.Data.TransStat = 'N(成功)'; break;
                    case 'C': result.Data.TransStat = 'C(失败)'; break;
                }
                result.Data.OrdDate = result.Data.OrdDate.substring(0, 4) + '-' + result.Data.OrdDate.substring(4, 6) + '-' + result.Data.OrdDate.substring(6, 8)
                $scope.GettenderInvest = result.Data;
            } else {
                $scope.GettenderInvest = ''
            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        commonFactory.ajax("/api/ChinaPnr/QueryTransStat", { ObjId: $scope.ordersearch.rechange, type: 'FREEZE' }, function (result) {//冻结解冻
            if (result.Code == 1 && result.Data) {
                switch (result.Data.TransStat) {
                    case 'N': result.Data.TransStat = 'N(无需解冻，对于解冻交易)'; break;
                    case 'F': result.Data.TransStat = 'F(冻结)'; break;
                    case 'U': result.Data.TransStat = 'U(已解冻)'; break;
                }
                result.Data.OrdDate = result.Data.OrdDate.substring(0, 4) + '-' + result.Data.OrdDate.substring(4, 6) + '-' + result.Data.OrdDate.substring(6, 8)
                $scope.GetTrxId = result.Data;
            } else {
                $scope.GetTrxId = ''
            }
        }, function () {
            toaster.pop('error', '失败', '后台未返回报错');
        }, "post");
        $timeout(function () {
            $scope.graybtn = false;
        }, 500);
    }
}]);